package com.example.anjia03_3z.controller;


import com.example.anjia03_3z.pojo.dto.ArticleAddNewDTO;
import com.example.anjia03_3z.pojo.vo.AdminListItemVO;
import com.example.anjia03_3z.pojo.vo.ArticleDetailVO;
import com.example.anjia03_3z.pojo.vo.ArticleListItemVO;
import com.example.anjia03_3z.security.LoginPrincipal;
import com.example.anjia03_3z.service.IArticleService;
import com.example.anjia03_3z.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@Slf4j
@RestController
@RequestMapping(path = "/articles")
public class ArticleController {

    @Autowired
    IArticleService articleService;

    @PostMapping("/add-new")
    public JsonResult<Void> addArticle( ArticleAddNewDTO articleAddNewDTO){
        articleService.addArticle(articleAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("查询文章列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("")
    public JsonResult<List<ArticleListItemVO>> list() {
        List<ArticleListItemVO> list = articleService.list();
        return JsonResult.ok(list);
    }

    @ApiOperation("查询文章")
    @ApiOperationSupport(order = 420)
    @GetMapping("/{id}")
    public JsonResult<ArticleDetailVO> get(@PathVariable Long id) {
        ArticleDetailVO articleById = articleService.getArticleById(id);
        return JsonResult.ok(articleById);
    }

}
